<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use app\common\model\Cash as CashModel;
use fast\Tree;

/**
 * 提现管理
 *
 * @icon   fa fa-list
 * @remark 用于统一管理网站的所有分类,分类可进行无限级分类,分类类型请在常规管理->系统配置->字典配置中添加
 */
class Cash extends Backend
{

    /**
     * @var \app\common\model\Category
     */
    protected $model = null;
    protected $categorylist = [];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('app\common\model\Cash');
        $this->model2 = model('app\common\model\Order');
    }


    public function cashlist(){
        return $this->view->fetch();
    }

    public function index()
    {

        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);

        if ($this->request->isAjax())
        {

            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            $id = $this->request->request("id");
            $type = $this->request->request("type");
            if($type == "3" || $type == "4"){
                //充值 3余额订单 4小时卡&微信支付
                $list =  db("order")
                    ->where("id in ($id)")
                    ->select();

                if($list){
                    foreach ($list as &$row) {
                        $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                        $row['from'] = "房源";
                        //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                        if($row['timing'] == 0){
                            $row['timing'] = "全日房";
                        }else if ($row['timing'] == 1){
                            $row['timing'] = "时租房";
                        }else{
                            $row['timing'] = "时租房";
                        }
                        if($row['pay_status'] == "0"){
                            $row['pay_statustext'] = "未支付";
                        }elseif ($row['pay_status'] == "1"){
                            $row['pay_statustext'] = "已预定";
                        }elseif ($row['pay_status'] == "2"){
                            $row['pay_statustext'] = "已入住";
                        }elseif ($row['pay_status'] == "3"){
                            $row['pay_statustext'] = "已完成";
                        }elseif ($row['pay_status'] == "4"){
                            $row['pay_statustext'] = "已取消";
                        }else{
                            $row['pay_statustext'] = "支付失败";
                        }

                        if($row['refund_status'] == "0"){
                            $row['refund_statustext'] = "无";
                        }elseif ($row['refund_status'] == "1"){
                            $row['refund_statustext'] = "无需退款";
                        }elseif ($row['refund_status'] == "2"){
                            $row['refund_statustext'] = "申请退款";
                        }elseif ($row['refund_status'] == "3"){
                            $row['refund_statustext'] = "已退款";
                        }elseif ($row['refund_status'] == "4"){
                            $row['refund_statustext'] = "退款失败";
                        }else{
                            $row['refund_statustext'] = "未知";
                        }

                    }
                    $result = array("rows" => $list);
                }else{
                    $result = array("rows" => []);
                }

                return json($result);
            }elseif ($type == 2){
                //现金需统计房源&套餐
                $allids = explode("||",$id);
                $oid = $allids[0];//订单表id
                $aid = $allids[1];//套餐表id
                $list = [];
                $alist = [];
                if($oid){
                    $list =  db("order")
                        ->where("id in ($oid)")
                        ->select();
                    if($list){
                        foreach ($list as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                            }else{
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }


                        }
                    }

                }
                if($aid){
                    $alist =  db("orderactivity")
                        ->where("id in ($aid)")
                        ->select();
                    if($alist){
                        foreach ($alist as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "套餐";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            $row['timing'] = "全日房";
                            $row['all_price'] = $row['price'];
                            $row['ballprice'] = 0;
                            $row['deposit'] = 0;
                            $row['number'] = 1;
                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已支付";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已预约";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }
                        }

                    }

                }

                $allresult = array_merge($list,$alist);
                $result = array("rows" => $allresult);
                return json($result);

            }elseif ($type == 5){
                //需统计房源&套餐 退款记录
                $allids = explode("||",$id);
                $oid1 = $allids[0];//订单表id //余额
                $oid2 = $allids[1];//订单表id //小时卡&微信
                $oid0 = $allids[2];//订单表id //微信
                $aid = $allids[3];//套餐表id
                $list1 = [];
                $list2 = [];
                $list0 = [];
                $alist = [];
                if($oid1){
                    $list1 =  db("order")
                        ->where("id in ($oid1)")
                        ->select();
                    if($list1){
                        foreach ($list1 as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                                $row['income'] = $row['totalprice'];
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                                $row['income'] = $row['price'];
                            }else{
                                $row['income'] = $row['price'];
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }


                        }
                    }

                }

                if($oid2){
                    $list2 =  db("order")
                        ->where("id in ($oid2)")
                        ->select();
                    if($list2){
                        foreach ($list2 as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                                $row['income'] = $row['totalprice'];
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                                $row['income'] = $row['price'];
                            }else{
                                $row['income'] = $row['price'];
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }


                        }
                    }

                }

                if($oid0){
                    $list0 =  db("order")
                        ->where("id in ($oid0)")
                        ->select();
                    if($list0){
                        foreach ($list0 as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                                $row['income'] = $row['totalprice'];
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                                $row['income'] = $row['price'];
                            }else{
                                $row['income'] = $row['price'];
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }


                        }
                    }

                }


                if($aid){
                    $alist =  db("orderactivity")
                        ->where("id in ($aid)")
                        ->select();
                    if($alist){
                        foreach ($alist as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "套餐";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            $row['timing'] = "全日房";
                            $row['all_price'] = $row['price'];
                            $row['ballprice'] = 0;
                            $row['deposit'] = 0;
                            $row['number'] = 1;
                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已支付";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已预约";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }
                        }

                    }

                }

                $allresult = array_merge($list1,$list2,$list0,$alist);
                $result = array("rows" => $allresult);
                return json($result);

            }elseif ($type == 12){
                //商家 退款明细
                //统计房源退款记录
                $allids = explode("||",$id);
                $oid1 = $allids[0];//订单表id //余额
                $oid2 = $allids[1];//订单表id //小时卡&微信
                $oid0 = $allids[2];//订单表id //微信
                $list1 = [];
                $list2 = [];
                $list0 = [];
                if($oid1){
                    $list1 =  db("order")
                        ->where("id in ($oid1)")
                        ->select();
                    if($list1){
                        foreach ($list1 as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                                $row['income'] = $row['totalprice'];
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                                $row['income'] = $row['price'];
                            }else{
                                $row['income'] = $row['price'];
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }


                        }
                    }

                }

                if($oid2){
                    $list2 =  db("order")
                        ->where("id in ($oid2)")
                        ->select();
                    if($list2){
                        foreach ($list2 as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                                $row['income'] = $row['totalprice'];
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                                $row['income'] = $row['price'];
                            }else{
                                $row['income'] = $row['price'];
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }


                        }
                    }

                }

                if($oid0){
                    $list0 =  db("order")
                        ->where("id in ($oid0)")
                        ->select();
                    if($list0){
                        foreach ($list0 as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                                $row['income'] = $row['totalprice'];
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                                $row['income'] = $row['price'];
                            }else{
                                $row['income'] = $row['price'];
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }


                        }
                    }

                }

                $allresult = array_merge($list1,$list2,$list0);
                $result = array("rows" => $allresult);
                return json($result);

            }elseif ($type == 10){
                //商家平台统计订单
                $allids = explode("||",$id);
                $oid = $allids[0];//微信支付 + 余额支付
                $oid2 = $allids[1];//小时卡支付订单
                $list = [];
                $list2 = [];
                if($oid){
                    $list =  db("order")
                        ->where("id in ($oid)")
                        ->select();
                    if($list){
                        foreach ($list as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                            }else{
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }


                        }
                    }

                }

                //小时卡收入微信部分 统计 wx_income
                if($oid2){
                    $list2 =  db("order")
                        ->where("id in ($oid2)")
                        ->select();
                    if($list2){
                        foreach ($list2 as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                            }else{
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }
                            //小时卡收入微信部分 统计 wx_income
                            $row['income'] = $row['wx_income'];


                        }
                    }

                }


                $allresult = array_merge($list,$list2);
                $result = array("rows" => $allresult);
                return json($result);

            }elseif ($type == 11){
                //商家平台统计小时卡订单
                $list = [];
                if($id){
                    $list =  db("order")
                        ->where("id in ($id)")
                        ->select();
                    if($list){
                        foreach ($list as &$row) {
                            $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                            $row['from'] = "房源";
                            //0全日房 1小时房（有结束时间） 2小时房（无结束时间）
                            if($row['timing'] == 0){
                                $row['timing'] = "全日房";
                            }else if ($row['timing'] == 1){
                                $row['timing'] = "时租房";
                            }else{
                                $row['timing'] = "时租房";
                            }

                            if($row['pay_status'] == "0"){
                                $row['pay_statustext'] = "未支付";
                            }elseif ($row['pay_status'] == "1"){
                                $row['pay_statustext'] = "已预定";
                            }elseif ($row['pay_status'] == "2"){
                                $row['pay_statustext'] = "已入住";
                            }elseif ($row['pay_status'] == "3"){
                                $row['pay_statustext'] = "已完成";
                            }elseif ($row['pay_status'] == "4"){
                                $row['pay_statustext'] = "已取消";
                            }else{
                                $row['pay_statustext'] = "支付失败";
                            }

                            if($row['refund_status'] == "0"){
                                $row['refund_statustext'] = "无";
                            }elseif ($row['refund_status'] == "1"){
                                $row['refund_statustext'] = "无需退款";
                            }elseif ($row['refund_status'] == "2"){
                                $row['refund_statustext'] = "申请退款";
                            }elseif ($row['refund_status'] == "3"){
                                $row['refund_statustext'] = "已退款";
                            }elseif ($row['refund_status'] == "4"){
                                $row['refund_statustext'] = "退款失败";
                            }else{
                                $row['refund_statustext'] = "未知";
                            }

                            //小时卡的收入 wx_income
                            $row['income'] = $row['wx_income'];

                        }
                    }

                }

                $allresult = $list;
                $result = array("rows" => $allresult);
                return json($result);

            }



        }

        return $this->view->fetch();
    }


    public function indexold2()
    {

        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);

        if ($this->request->isAjax())
        {

            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            $id = $this->request->request("id");

            $offset = $this->request->request("offset");


            $list =  db("order")
                ->where("id in ($id)")
                ->limit($offset,10)
                ->select();




            foreach ($list as &$row) {
                    //酒店名称
                     $hotel = db("hotels")->where(['hid'=>$row['hotelid']])->field("hotelname")->find();
                     $row['htitle'] = $hotel['hotelname'];
                    //房间名称
                     $room = db("house")->where(['id'=>$row['room_id']])->field("h_title")->find();
                     $row['roomtitle'] = $room['h_title'];

                     $row['pay_time'] = date("Y-m-d H:i:s",$row['pay_time']);
                     //获取申请时间 审批时间
                     $oid = $row['id'];
                     $appinfo = db("cash")->where("find_in_set($oid,`oids`)")->find();
                     $row['appcreatetime'] = date("Y-m-d H:i:s",$appinfo['createtime']);
                     $row['appupdtime'] = date("Y-m-d H:i:s",$appinfo['updtime']);
                     if($appinfo['status'] == 1){
                         $row['appstatus'] = "申请中";
                     }else{
                         $row['appstatus'] = "已处理";
                     }


            }

            $total = db("order")->where("id in ($id)")->count();

            $result = array("total" => $total, "rows" => $list);


            return json($result);

        }

        return $this->view->fetch();
    }

    /**
     * 查看
     */
    public function indexold()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            $search = $this->request->request("search");
            $type = $this->request->request("type");

            //构造父类select列表选项数据
            $list = [];

            foreach ($this->categorylist as $k => $v) {
                if ($search) {
                    if ($v['type'] == $type && stripos($v['name'], $search) !== false || stripos($v['nickname'], $search) !== false) {
                        if ($type == "all" || $type == null) {
                            $list = $this->categorylist;
                        } else {
                            $list[] = $v;
                        }
                    }
                } else {
                    if ($type == "all" || $type == null) {
                        $list = $this->categorylist;
                    } elseif ($v['type'] == $type) {
                        $list[] = $v;
                    }
                }
            }

            $total = count($list);
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

    /**
     * 编辑
     */
    public function edit($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds)) {
            if (!in_array($row[$this->dataLimitField], $adminIds)) {
                $this->error(__('You have no permission'));
            }
        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                $params = $this->preExcludeFields($params);


                try {
                    //是否采用模型验证
                    if ($this->modelValidate) {
                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
                        $row->validate($validate);
                    }
                    $result = $row->allowField(true)->save($params);
                    if ($result !== false) {
                        $this->success();
                    } else {
                        $this->error($row->getError());
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        $this->view->assign("row", $row);
        return $this->view->fetch();
    }


    /**
     * Selectpage搜索
     *
     * @internal
     */
    public function selectpage()
    {
        return parent::selectpage();
    }
}
